<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
-->
<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="true"
    :okAuth="'shop:apply:soReturnApply:edit'"
    @register="registerDrawer"
    @ok="handleSubmit"
    width="95%"
  >
    <template #title>
      <Icon :icon="getTitle.icon" class="pr-1 m-1" />
      <span> {{ getTitle.value }} </span>
    </template>
    <BasicForm @register="registerForm">
      <template #rdsSelect>
        <ListSelect
          v-model:value="itemCodes"
          :labelValue="itemNames"
          selectType="basInvSelect-orderback"
          :checkbox="true"
          :params="queryParams"
          :selectList="listSelectRef"
          @select="handSelect"
        />
      </template>
      <template #soReturnApplyRdsList>
        <BasicTable
          @register="registerSoReturnApplyRdsTable"
          @row-click="handleSoReturnApplyRdsRowClick"
          @edit-change="rowChange"
        />
        <a-button
          class="mt-2"
          @click="handleSoReturnApplyRdsAdd"
          v-auth="'shop:apply:soReturnApply:edit'"
        >
          <Icon icon="ant-design:plus-circle-outlined" /> {{ t('新增') }}
        </a-button>
      </template>
    </BasicForm>
  </BasicDrawer>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsShopApplySoReturnApplyForm',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref, computed } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { BasicTable, useTable } from '/@/components/Table';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import {
    SoReturnApply,
    soReturnApplySave,
    soReturnApplyForm,
  } from '/@/api/shop/apply/soReturnApply';
  import { getSelectCurCus, findSelectMnCusListData } from '/@/api/shop/order/soAdvanceOrder';
  import { ListSelect } from '/@/components/ListSelect';
  import { basWarehousetreeData } from '/@/api/bas/house/basWarehouse';

  const emit = defineEmits(['success', 'register']);

  const { t } = useI18n('shop.apply.soReturnApply');
  const { showMessage } = useMessage();
  const record = ref<SoReturnApply>({} as SoReturnApply);
  const getTitle = computed(() => ({
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: record.value.isNewRecord ? t('新增退货申请单') : t('编辑退货申请单'),
  }));
  const itemCodes = ref('');
  const itemNames = ref('');
  let listSelectRef = ref([]);
  let queryParams = ref({});
  const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] =
    useForm();

  const [registerSoReturnApplyRdsTable, soReturnApplyRdsTable] = useTable({
    actionColumn: {
      width: 60,
      actions: (record: Recordable) => [
        {
          icon: 'ant-design:delete-outlined',
          color: 'error',
          popConfirm: {
            title: '是否确认删除',
            confirm: handleSoReturnApplyRdsDelete.bind(this, record),
          },
          auth: 'shop:apply:soReturnApply:edit',
        },
      ],
    },
    rowKey: 'id',
    pagination: false,
    bordered: true,
    size: 'small',
    inset: true,
  });

  async function setSoReturnApplyRdsTableData(_res: Recordable) {
    soReturnApplyRdsTable.setColumns([
      {
        title: t('仓库'),
        dataIndex: 'whcode',
        dataLabel: 'basWare.whname',
        width: 180,
        align: 'left',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'TreeSelect',
        editComponentProps: {
          allowClear: true,
          api: basWarehousetreeData,
          params: { isAll: false },
        },
        editRule: true,
      },
      {
        title: t('存货编码'),
        dataIndex: 'cinvcode',
        width: 130,
        align: 'left',
        // editRow: true,
        // editComponent: 'Input',
        // editComponentProps: {
        //   maxlength: 64,
        // },
        // editRule: false,
      },
      {
        title: t('存货名称'),
        dataIndex: 'basInv.cinvname',
        width: 240,
        align: 'left',
      },
      {
        title: t('换算率'),
        // dataIndex: 'basInv.ichangrate',
        dataIndex: 'ichangerate',
        width: 80,
        align: 'center',
      },
      {
        title: t('含税单价'),
        dataIndex: 'itaxunitprice',
        width: 80,
        align: 'center',
      },
      {
        title: t('价税合计'),
        dataIndex: 'isum',
        width: 80,
        align: 'center',
      },
      {
        title: t('业绩金额'),
        dataIndex: 'yjMoney',
        width: 80,
        align: 'center',
        // editRow: true,
        // editComponent: 'InputNumber',
        // editComponentProps: {
        //   maxlength: 16,
        // },
        // editRule: false,
      },
      {
        title: t('税率'),
        dataIndex: 'itaxrate',
        width: 80,
        align: 'center',
      },
      {
        title: t('扣率'),
        dataIndex: 'klRate',
        width: 80,
        align: 'center',
        // editRow: true,
        // editComponent: 'InputNumber',
        // editComponentProps: {
        //   maxlength: 51,
        // },
        // editRule: false,
      },
      {
        title: t('折扣额'),
        dataIndex: 'idiscount',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'InputNumber',
        editComponentProps: {
          maxlength: 16,
        },
        editRule: false,
      },
      {
        title: t('申请数量'),
        dataIndex: 'applyIqty',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'InputNumber',
        editComponentProps: {
          maxlength: 8,
        },
        editRule: true,
      },
      {
        title: t('申请件数'),
        dataIndex: 'applyInum',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'InputNumber',
        editComponentProps: {
          maxlength: 51,
        },
        editRule: true,
      },

      {
        title: t('使用返利金额'),
        dataIndex: 'flMoney',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'InputNumber',
        editComponentProps: {
          maxlength: 16,
        },
        editRule: false,
      },
      {
        title: t('使用促销金额'),
        dataIndex: 'cxMoney',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'InputNumber',
        editComponentProps: {
          maxlength: 16,
        },
        editRule: false,
      },

      {
        title: t('是否赠品'),
        dataIndex: 'bgift',
        width: 130,
        align: 'center',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'Select',
        editComponentProps: {
          dictType: 'sys_yes_no',
        },
        editRule: true,
        dictType: 'sys_yes_no',
      },
      {
        title: t('退货原因'),
        dataIndex: 'remarks',
        width: 130,
        align: 'left',
        editable: true,
        edit: true,
        editRow: true,
        editComponent: 'Input',
        editComponentProps: {
          maxlength: 500,
        },
        editRule: false,
      },
    ]);
    soReturnApplyRdsTable.setTableData(record.value.soReturnApplyRdsList || []);
  }

  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    setDrawerProps({ loading: true });
    await resetFields();
    const res = await soReturnApplyForm({ code: data.code, cusCode: data.cusCode });
    record.value = (res.soReturnApply || {}) as SoReturnApply;
    record.value = {
      ...data,
      ...record.value,
    };
    record.value.__t = new Date().getTime();
    setDrawerProps({ showOkBtn: record.value.auditStatus == '1' ? false : true });
    record.value.soReturnApplyRdsList.forEach((item) => {
      item.idiscount = item.idiscount ? item.idiscount : 0;
      item.flMoney = item.flMoney ? item.flMoney : 0;
      item.cxMoney = item.cxMoney ? item.cxMoney : 0;
    });

    let curCus = await getSelectCurCus({ code: record.value.cusCode });
    queryParams.value = {
      cusCode: record.value.cusCode,
    };
    let inputFormSchemas: FormSchema[] = [
      {
        label: t('单据号'),
        field: 'code',
        dynamicDisabled: true,
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
        colProps: { lg: 24, md: 24 },
      },
      {
        label: t('客户编码'),
        field: 'cusCode',
        dynamicDisabled: true,
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
        colProps: { lg: 12, md: 24 },
      },
      {
        label: t('客户名称'),
        field: 'basCus.name',
        dynamicDisabled: true,
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
        colProps: { lg: 12, md: 24 },
      },
      {
        label: t('单据日期'),
        field: 'ddate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
        required: true,
        show: false,
      },
      {
        label: t('业务类型'),
        field: 'cbustype',
        component: 'Select',
        componentProps: {
          dictType: 'bus_type',
          allowClear: true,
        },
        required: true,
        itemProps: { validateTrigger: 'blur' },
      },
      {
        label: t('销售部门'),
        field: 'deptName',
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
      },
      {
        label: t('核发门店'),
        field: 'hfdmCode',
        fieldLabel: 'hfdmName',
        component: 'TreeSelect',
        componentProps: {
          api: findSelectMnCusListData,
          params: {
            isLoadUser: true,
            userIdPrefix: '',
            code: record.value.cusCode,
            isShowCode: true,
            isAll: true,
          },
          canSelectParent: false,
          allowClear: true,
        },
        ifShow: curCus.bmn == '0' && curCus.bsjmn == '0' ? false : true,
        required: curCus.bmn == '1' ? true : false,
        itemProps: { validateTrigger: 'blur' },
      },
      {
        label: t('是否首批'),
        field: 'bsp',
        component: 'Select',
        componentProps: {
          dictType: 'bus_is_first',
          allowClear: true,
        },
        required: true,
        itemProps: { validateTrigger: 'blur' },
      },
      {
        label: t('是否包邮'),
        field: 'bby',
        component: 'Select',
        componentProps: {
          dictType: 'bus_is_free',
          allowClear: true,
        },
        required: true,
        itemProps: { validateTrigger: 'blur' },
      },
      {
        label: t('物流公司'),
        field: 'wlComp',
        component: 'Input',
        componentProps: {
          maxlength: 255,
        },
      },
      {
        label: t('物流单号'),
        field: 'wlNo',
        component: 'Input',
        componentProps: {
          maxlength: 255,
        },
      },
      {
        label: t('退回理由'),
        field: 'remarks',
        component: 'InputTextArea',
        componentProps: {
          maxlength: 500,
        },
        colProps: { lg: 24, md: 24 },
      },
      {
        label: t('经销商余额'),
        field: 'zhMoney',
        component: 'Input',
        dynamicDisabled: true,
        defaultValue: '0.00',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
        ],
      },

      {
        label: t('经销商返利余额'),
        field: 'flMoney',
        component: 'Input',
        dynamicDisabled: true,
        defaultValue: '0.00',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
        ],
      },
      {
        label: t('经销商促销余额'),
        field: 'cxMoney',
        component: 'Input',
        dynamicDisabled: true,
        defaultValue: '0.00',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
        ],
      },
      {
        label: t('使用账户金额'),
        field: 'useZhMoney',
        dynamicDisabled: true,
        defaultValue: '0.00',
        component: 'Input',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { required: false },
          {
            validator(_rule, value) {
              return new Promise((resolve, reject) => {
                if (
                  Number(getFieldsValue().useZhMoney) > 0
                  // (Number(getFieldsValue().useCxMoney) + Number(getFieldsValue().useFlMoney)) > Number(getFieldsValue().useZhMoney)
                ) {
                  reject(t('使用返利促销之和不能超过使用账户金额'));
                } else {
                  resolve();
                }
              });
            },
          },
        ],
      },
      {
        label: t('使用返利金额'),
        field: 'useFlMoney',
        dynamicDisabled: true,
        defaultValue: '0.00',
        component: 'Input',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
        ],
      },
      {
        label: t('使用促销金额'),
        field: 'useCxMoney',
        dynamicDisabled: true,
        defaultValue: '0.00',
        component: 'Input',
        componentProps: {
          maxlength: 16,
        },
        colProps: { lg: 8, md: 24 },
        rules: [
          { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
        ],
      },

      // {
      //   label: t('审核人'),
      //   field: 'auditor',
      //   component: 'Input',
      //   componentProps: {
      //     maxlength: 255,
      //   },
      // },
      // {
      //   label: t('审核日期'),
      //   field: 'auditDate',
      //   component: 'DatePicker',
      //   componentProps: {
      //     format: 'YYYY-MM-DD HH:mm',
      //     showTime: { format: 'HH:mm' },
      //   },
      // },
      // {
      //   label: t('审核状态'),
      //   field: 'auditStatus',
      //   component: 'Input',
      //   componentProps: {
      //     maxlength: 20,
      //   },
      // },

      {
        label: t('协同路线'),
        field: 'croute',
        dynamicDisabled: true,
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
        colProps: { lg: 12, md: 24 },
      },
      {
        label: t('协同描述'),
        field: 'crouteDesc',
        dynamicDisabled: true,
        component: 'Input',
        componentProps: {
          maxlength: 200,
        },
        required: true,
        colProps: { lg: 12, md: 24 },
      },
      {
        label: t('存货'),
        field: 'selIds',
        component: 'Input',
        colProps: { lg: 24, md: 24 },
        slot: 'rdsSelect',
        show: false,
      },
      {
        label: t(''),
        field: 'soReturnApplyRdsList',
        component: 'Input',
        colProps: { lg: 24, md: 24 },
        slot: 'soReturnApplyRdsList',
      },
    ];

    await setProps({
      labelWidth: 140,
      schemas: inputFormSchemas,
      baseColProps: { lg: 12, md: 24 },
    });
    setFieldsValue(record.value);
    setSoReturnApplyRdsTableData(res);
    setDrawerProps({ loading: false });
  });

  async function rowChange({ column, value, record }) {
    // 输入数量
    if (column.dataIndex == 'applyIqty') {
      if (value > 0) {
        value = -value;
      }
      record.applyIqty = value;
      record.applyInum = (value / record.ichangerate).toFixed(4);
      record.isum = value * record.itaxunitprice;

      let arr = await soReturnApplyRdsTable.getDataSource();
      let flSum = 0;
      let cxSum = 0;
      let isumSum = 0;
      arr.forEach((item) => {
        flSum += item.flMoney;
        cxSum += item.cxMoney;
        isumSum += Number(item.isum);
      });
      let useZhMoney = isumSum - flSum - cxSum;
      setFieldsValue({
        ...getFieldsValue(),
        useZhMoney,
      });
    }

    // 输入件数
    if (column.dataIndex == 'applyInum') {
      if (value > 0) {
        value = -value;
      }
      record.applyIqty = Math.round(value * record.ichangerate);
      record.isum = record.itaxunitprice * record.applyIqty;
      record.applyInum = (record.applyIqty / record.ichangerate).toFixed(4);
      let arr = await soReturnApplyRdsTable.getDataSource();
      let flSum = 0;
      let cxSum = 0;
      let isumSum = 0;
      arr.forEach((item) => {
        flSum += item.flMoney;
        cxSum += item.cxMoney;
        isumSum += Number(item.isum);
      });
      let useZhMoney = isumSum - flSum - cxSum;
      setFieldsValue({
        ...getFieldsValue(),
        useZhMoney,
      });
    }

    // 输入折扣额
    if (column.dataIndex == 'idiscount') {
      if (value > 0) {
        value = -value;
      }
      record.idiscount = value;
    }
    if (record.isum) {
      record.klRate = ((record.isum / (record.idiscount + record.isum)) * 100).toFixed(2);
    }

    // 输入返利
    if (column.dataIndex == 'flMoney') {
      if (value > 0) {
        value = -value;
      }
      record.flMoney = value;
      let arr = await soReturnApplyRdsTable.getDataSource();
      let flSum = 0;
      let cxSum = 0;
      let isumSum = 0;
      arr.forEach((item) => {
        flSum += item.flMoney;
        cxSum += item.cxMoney;
        isumSum += Number(item.isum);
      });
      let useZhMoney = isumSum - flSum - cxSum;

      setFieldsValue({
        ...getFieldsValue(),
        useFlMoney: flSum,
        useZhMoney,
      });
    }
    // 输入返利
    if (column.dataIndex == 'cxMoney') {
      if (value > 0) {
        value = -value;
      }
      record.cxMoney = value;
      let arr = await soReturnApplyRdsTable.getDataSource();
      let flSum = 0;
      let cxSum = 0;
      let isumSum = 0;
      arr.forEach((item) => {
        flSum += item.flMoney;
        cxSum += item.cxMoney;
        isumSum += Number(item.isum);
      });
      let useZhMoney = isumSum - flSum - cxSum;
      setFieldsValue({
        ...getFieldsValue(),
        useCxMoney: cxSum,
        useZhMoney,
      });
    }

    if (record.cxMoney == 0 || !record.cxMoney) {
      record.yjMoney = record.isum;
    } else {
      record.yjMoney = 0;
    }

    console.log(column, value, record);

    if (column.dataIndex == 'bgift') {
      record.bgift = value;
      if (record.bgift == 1) {
        record.isum = 0;
        record.idiscount = 0;
        record.flMoney = 0;
        record.cxMoney = 0;
        record.yjMoney = 0;
        record.klRate = '100.00';

        let arr = await soReturnApplyRdsTable.getDataSource();
        let flSum = 0;
        let cxSum = 0;
        let isumSum = 0;
        arr.forEach((item) => {
          flSum += item.flMoney;
          cxSum += item.cxMoney;
          isumSum += Number(item.isum);
        });
        let useZhMoney = isumSum - flSum - cxSum;
        setFieldsValue({
          ...getFieldsValue(),
          useCxMoney: cxSum,
          useFlMoney: flSum,
          useZhMoney,
        });
      }
      if (record.bgift == 0) {
        record.isum = record.applyIqty * record.itaxunitprice;
        record.idiscount = record.idiscount;
        record.flMoney = record.flMoney;
        record.cxMoney = record.cxMoney;
        record.yjMoney = record.isum;
        // record.klRate = record.klRate
        if (record.isum) {
          record.klRate = ((record.isum / (record.idiscount + record.isum)) * 100).toFixed(2);
        }

        let arr = await soReturnApplyRdsTable.getDataSource();
        let flSum = 0;
        let cxSum = 0;
        let isumSum = 0;
        arr.forEach((item) => {
          flSum += item.flMoney;
          cxSum += item.cxMoney;
          isumSum += Number(item.isum);
        });
        let useZhMoney = isumSum - flSum - cxSum;
        setFieldsValue({
          ...getFieldsValue(),
          useCxMoney: cxSum,
          useFlMoney: flSum,
          useZhMoney,
        });
      }
    }
  }

  function handleSoReturnApplyRdsRowClick(record: Recordable) {
    record.onEdit?.(true, false);
  }

  function handleSoReturnApplyRdsAdd() {
    console.log(1112233);
    listSelectRef.value = [];
    document.getElementById('form_item_selIds')?.click();
    // soReturnApplyRdsTable.insertTableDataRecord({
    //   id: new Date().getTime(),
    //   isNewRecord: true,
    //   editable: true,
    // });
  }

  async function handleSoReturnApplyRdsDelete(record: Recordable) {
    soReturnApplyRdsTable.deleteTableDataRecord(record);
    if (soReturnApplyRdsTable.getDataSource().length == 0) {
      setFieldsValue({
        ...getFieldsValue(),
        croute: '',
        crouteDesc: '',
      });
    }
    let arr = await soReturnApplyRdsTable.getDataSource();
    let flSum = 0;
    let cxSum = 0;
    let isumSum = 0;
    arr.forEach((item) => {
      flSum += item.flMoney;
      cxSum += item.cxMoney;
      isumSum += Number(item.isum);
    });
    let useZhMoney = isumSum - flSum - cxSum;
    setFieldsValue({
      ...getFieldsValue(),
      useCxMoney: cxSum,
      useFlMoney: flSum,
      useZhMoney,
    });
  }

  async function getSoReturnApplyRdsList() {
    let soReturnApplyRdsListValid = true;
    let soReturnApplyRdsList: Recordable[] = [];
    for (const record of soReturnApplyRdsTable.getDataSource()) {
      if (!(await record.onEdit?.(false, true))) {
        soReturnApplyRdsListValid = false;
      }
      soReturnApplyRdsList.push({
        ...record,
        id: !!record.isNewRecord ? '' : record.id,
      });
    }
    for (const record of soReturnApplyRdsTable.getDelDataSource()) {
      if (!!record.isNewRecord) continue;
      soReturnApplyRdsList.push({
        ...record,
        status: '1',
      });
    }
    if (!soReturnApplyRdsListValid) {
      throw { errorFields: [{ name: ['soReturnApplyRdsList'] }] };
    }
    return soReturnApplyRdsList;
  }

  async function handleSubmit() {
    try {
      const data = await validate();
      setDrawerProps({ confirmLoading: true });
      const params: any = {
        isNewRecord: record.value.isNewRecord,
        code: record.value.code,
      };
      data.soReturnApplyRdsList = await getSoReturnApplyRdsList();
      // console.log('submit', params, data, record);
      const res = await soReturnApplySave(params, data);
      showMessage(res.message);
      setTimeout(closeDrawer);
      emit('success', data);
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage(t('您填写的信息有误，请根据提示修正。'));
      }
      console.log('error', error);
    } finally {
      setDrawerProps({ confirmLoading: false });
    }
  }
  /**
   * 选择
   * @param selectData
   */
  function handSelect(selectData) {
    if (getFieldsValue().croute) {
      let flag = true;
      let croute = selectData[0].croute;
      selectData.forEach((item) => {
        if (item.croute != croute) {
          flag = false;
        }
      });
      if (!flag) {
        showMessage(t('请选择相同的协同路线！'));
      } else {
        console.log(soReturnApplyRdsTable.getDataSource(), '子表信息-----');

        selectData.forEach((item) => {
          let flag = true;
          soReturnApplyRdsTable.getDataSource().forEach((res) => {
            if (res.cinvcode == item.cinvcode) {
              flag = false;
            }
          });
          if (flag) {
            soReturnApplyRdsTable.insertTableDataRecord({
              ...item,
              id: '',
              editable: true,
              isNewRecord: true,
              // fretailprice: item.itaxunitprice,
              basInv: {
                cinvname: item.cinvname,
                ichangrate: item.ichangrate,
              },
              ichangerate:item.ichangrate,
              itaxunitprice: item.appPrice,
              klRate: '100.00',
              idiscount: 0,
              bgift: '0',
              isum: 0,
              yjMoney: 0,
              cxMoney: 0,
              flMoney: 0,
            });
          }
        });
      }
    } else {
      console.log(soReturnApplyRdsTable.getDataSource(), '子表信息-----');
      setFieldsValue({
        ...getFieldsValue(),
        croute: selectData[0].croute,
        crouteDesc: selectData[0].routeDesc,
      });
      selectData.forEach((item) => {
        soReturnApplyRdsTable.insertTableDataRecord({
          id: '',
          editable: true,
          ...item,
          isNewRecord: true,
          // fretailprice: item.appPrice,
          basInv: {
            cinvname: item.cinvname,
            ichangrate: item.ichangrate,
          },
          ichangerate:item.ichangrate,
          itaxunitprice: item.appPrice,
          klRate: '100.00',
          idiscount: 0,
          bgift: '0',
          isum: 0,
          yjMoney: 0,
          cxMoney: 0,
          flMoney: 0,
        });
      });
    }

    // if (selectType.value === 'flowSelect') {
    // selectData.forEach((item) => {
    //   soReturnApplyRdsTable.insertTableDataRecord({
    //     id: '',
    //     editable: true,
    //     ...item,
    //     isNewRecord: true,
    //     // iqty: item.iqty - (item.fcQty || 0),
    //   });
    // });
    // } else {
    //   m8OrderFlowWxOutRdsTable.insertTableDataRecord({
    //     id: new Date().getTime(),
    //     isNewRecord: true,
    //     editable: true,
    //   });
    // }
  }
</script>
<style lang="less" scoped>
  :deep(.jeesite-editable-cell__action) {
    display: none;
  }

  /* .jeesite-editable-cell__action {
    display: none;
  } */

  :deep(.edit-cell-align-center) {
    width: 100% !important;
  }
</style>
